#include "mainwindow.h"

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
{
   connect(& exit, SIGNAL (clicked()), this, SLOT (close()));
   connect(& dir, SIGNAL (clicked()), this, SLOT (dirr()));
    connect(& save, SIGNAL (clicked()), this, SLOT (write()));
   connect (& box, SIGNAL (currentIndexChanged(QString)), this, SLOT (view()));
}

MainWindow::~MainWindow()
{
}
 void MainWindow::dirr()
    {
        str = QFileDialog::getExistingDirectory(this, "Open Directory");
        QDir folder(str);
        QStringList filters;
        filters << "*.txt";
        list=folder.entryList(filters);
        box.addItems(list);
    }
 void MainWindow::view()
 {
     QFile chtenie(str+char(92)+box.currentText());
     QString text;
     if(chtenie.open(QIODevice::ReadOnly))
     {
         QTextStream wer(&chtenie);
         text=wer.readAll();

     }
     edit();.setText(text);
 }
void MainWindow::write()
{
QFile write(str+char(92)+box.currentText());
write.open(QIODevice::WriteOnly);
QTextStream textt;
textt.setDevice(&write);
textt<<edit.toPlainText();
write.close();

}
